<?php
namespace BoxEdu\Controller\Admin;
//use Think\Controller;
class AttachController extends CommonController {
	public function _initialize() {
		parent::_initialize();
		$this->class_id = I('class_id');
		$this->subject_data = BoxModel("edu_subject")->where(array('subjectid' => $this->class_id))->find();

	}

	/******软件列表****/
	public function index() {
		$where = "1";
		if ($this->kw = I('kw')) {
			$where .= " and  (atttitle like '%$this->kw%' )";
		}
		if ($this->class_id = I('class_id')) {
			$where .= " and class_id='$this->class_id'";
		}
		$model = BoxModel('edu_attach');
		$data = $model->get($where, 10, "order_by");
		$this->data = $data['list'];
		$this->show_page($data['pager']);
		$this->display();

	}

	/*****添加*****/
	public function add() {
		$this->memuNav = "index";
		$attid = I('attid');
		$model = BoxModel('edu_attach');
		$this->data = $model->load($attid);
		$guide_step = BoxModel("system_template")->where(array('name' => 'guide-step'))->find();
		$this->guide_step = stripslashes(htmlspecialchars_decode($guide_step['tpl_content']));
		//	dump($this->guide_step);
		//	dump( $this->data);
		if (IS_POST) {
			$row = $model->create();
			$info = $this->_upload("/subject/");
			// dump($info);exit();
			if (is_array($info)) {
				$row['att_img'] = $info['picname']['savepath'] . $info['picname']['savename'];
			}
			if ($attid = I('attid')) {
				$model->save($row);
			} else {
				$row['attinputtime'] = time();
				$model->add($row);
			}
			$this->jump("保存成功", U('index', array('class_id' => $this->class_id)));
		}
		$this->display();
	}

	/******删除****/
	public function del() {
		$attid = I('attid');
		$this->data = BoxModel("edu_attach")->load($attid);
		$r = BoxModel('edu_attach')->where("attid='$attid'")->delete();
		$this->jump("操作成功");
	}

}